::获取当前日期和时间作为文件夹名
for /f "tokens=1,2,3,* delims=-|.|/ " %%a in ("%date%") do (
set currenttime=%%a%%b%%c
) 
for /f "tokens=1,2,3,* delims=:|. " %%a in ("%time%") do (
set currenttime=%currenttime%%%a%%b%%c
) 
::创建文件夹
md %currenttime%
::查询可用的摄像头，默认第一个
ffmpeg.exe -list_devices true -f dshow -i dummy 2> tmp.log
for /f "tokens=*" %%i in ('find /i "[dshow" "tmp.log"') do (

	if exist ok.bin (
		for /f tokens^=2^ delims^=^" %%j in ("%%i") do (
		::for /f "tokens=2 delims=]" %%a in ("%%i") do (
			set videodevice=%%j
		) 
		del /q "ok.bin"
	)
	
	echo %%i | find /N "DirectShow video devices">nul && echo "ok" >ok.bin
)
del /q "tmp.log"
::录制文件并且添加时间戳，默认1800秒一个文件
for /l %%m in (1,1,10000) do (
ffmpeg.exe -f dshow -s 640x480 -i video="%videodevice%" -t 1800 -vb 512k -bf 0 -vf drawtext="fontfile=arial.ttf:x=w-tw:fontcolor=blue:fontsize=30:text='%%{localtime}'" -vcodec libx264  %currenttime%/Record_%%m.mp4
::-f segment -segment_time 120 %currenttime%/Record_%%03d.ts
::-f hls -hls_list_size 0 -hls_time 60 %currenttime%/output.m3u8
)